﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SavoryDL;

namespace SavoryBL
{
   public class SavoryUserDetails
    {
       public DataSet GetUserProfileDetailsByUserID(int userID)
       {

           DataSet ds = null;
           try
           {
               Savory_ParameterList par = new Savory_ParameterList();
               par.AddIntParameter("@UserID", userID);
               ds = Savory_DBServices.GetDataSet("GetUserProfileByUserID", System.Data.CommandType.StoredProcedure, par);

           }
           catch (Exception ex)
           {

           }
           finally
           {

           }
           return ds;
       }
       public ResponseStatus UserChangePassword(int userID, string oldPwd, string newPwd)
       {

           ResponseStatus status = ResponseStatus.Failure;
           try
           {
               Savory_ParameterList par = new Savory_ParameterList();
               par.AddIntParameter("@UserID", userID);             
               par.AddStringParameter("@Password", oldPwd);
               par.AddStringParameter("@NewPassword", newPwd);
               Int32 returnStatus = Savory_DBServices.ExecuteQuery("UserChangePassword", System.Data.CommandType.StoredProcedure, par);

               if (returnStatus == 0)
               {
                   status = ResponseStatus.InvalidOldPassword;
               }
               else if (returnStatus == 1)
               {
                   status = ResponseStatus.Success;
               }
               else if (returnStatus == -1)
               {
                   status = ResponseStatus.Failure;
               }
           }
           catch (Exception ex)
           {

           }
           finally
           {

           }

           return status;
       }
       public ResponseStatus UserUpdateAccountDetails(string firstName,string lastName, string contactNo1, string emailID,string countryID,string city,int userID)
       {

           ResponseStatus status = ResponseStatus.Failure;
           try
           {
               Savory_ParameterList par = new Savory_ParameterList();
               par.AddStringParameter("@FirstName", firstName);
               par.AddStringParameter("@LastName", lastName);
               par.AddStringParameter("@ContactNo1", contactNo1);
               par.AddStringParameter("@EmailID", emailID);
               par.AddStringParameter("@CountryID", countryID);
               par.AddStringParameter("@City", city);
               par.AddIntParameter("@UserID", userID);
               Int32 returnStatus = Savory_DBServices.ExecuteQuery("UserAccountUpdate", System.Data.CommandType.StoredProcedure, par);

               if (returnStatus == 0)
               {
                   status = ResponseStatus.InvalidOldPassword;
               }
               else if (returnStatus == 1)
               {
                   status = ResponseStatus.Success;
               }
               else if (returnStatus == -1)
               {
                   status = ResponseStatus.Failure;
               }
           }
           catch (Exception ex)
           {

           }
           finally
           {

           }

           return status;
       }
       public String GetCountryNameByCountryID(int CountryID)
       {

           DataSet ds = null;
           string country = string.Empty;
           try
           {
               Savory_ParameterList par = new Savory_ParameterList();
               par.AddIntParameter("@CountryID", CountryID);
               ds = Savory_DBServices.GetDataSet("GetCountryByCountryID", System.Data.CommandType.StoredProcedure, par);
               if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
               {
                   country = ds.Tables[0].Rows[0]["Country"].ToString();
               }
           }
           catch (Exception ex)
           {

           }
           finally
           {

           }
           return country;
       }
       public bool IsMemberApprovedByAdmin(string userName,string password)
       {
           bool IsActive = false;
           DataSet ds = null;
           try
           {
               Savory_ParameterList par = new Savory_ParameterList();
               par.AddStringParameter("@UserName", userName);
               par.AddStringParameter("@Password", password);
               ds = Savory_DBServices.GetDataSet("AuthenticateUser", System.Data.CommandType.StoredProcedure, par);
               if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
               {
                   IsActive = Convert.ToBoolean(ds.Tables[0].Rows[0]["IsActive"].ToString());
               }

           }
           catch (Exception ex)
           {

           }
           finally
           {

           }
           return IsActive;
       }
       public ResponseStatus InsertCompanyProductPosted(string Country, string City, string ProductName, string Year, string Description, string Picture, string Picture1, string @Picture2, string Picture3, string @Picture4, int UserID)

       {

           ResponseStatus status = ResponseStatus.Failure;
           try
           {
               Savory_ParameterList par = new Savory_ParameterList();
               par.AddStringParameter("@Country", Country);
               par.AddStringParameter("@City", City);
               par.AddStringParameter("@ProductName", ProductName);
               par.AddStringParameter("@Year", Year);
               par.AddStringParameter("@Description", Description);
               par.AddFloatParameter("@TotalPrice", 0);
               par.AddStringParameter("@Picture", Picture);
               par.AddStringParameter("@Picture1", Picture1);
               par.AddStringParameter("@Picture2", Picture2);
               par.AddStringParameter("@Picture3", Picture3);
               par.AddStringParameter("@Picture4", Picture4);            
               par.AddIntParameter("@UserID", UserID);
               Int32 returnStatus = Savory_DBServices.ExecuteQuery("InsertCompanyProductPosted", System.Data.CommandType.StoredProcedure, par);

               if (returnStatus == 0)
               {
                   status = ResponseStatus.InvalidOldPassword;
               }
               else if (returnStatus == 1)
               {
                   status = ResponseStatus.Success;
               }
               else if (returnStatus == -1)
               {
                   status = ResponseStatus.Failure;
               }
           }
           catch (Exception ex)
           {

           }
           finally
           {

           }

           return status;
       }

       public DataSet GetOfficeandAgentsList(string Country, string City, string UserID)
       {
           DataSet ds = null;
           try
           {
               Savory_ParameterList par = new Savory_ParameterList();
               par.AddStringParameter("@UserID", UserID);
               par.AddStringParameter("@Country", Country);
               par.AddStringParameter("@City", City);
               ds = Savory_DBServices.GetDataSet("GetAgentOfficeDetails", System.Data.CommandType.StoredProcedure, par);
           }
           catch (Exception ex)
           {

           }
           finally
           {

           }
           return ds;
       }

       public ResponseStatus AddUser(string UserType, string firstName, string lastName, string Office, string contactNo1, string contactNo2, string MobileNo1, string MobileNo2, string emailID, string Password, string countryID, string city, int userID, bool IsNewslatter,string WebSite, string Fax, string Street )
       {

           ResponseStatus status = ResponseStatus.Failure;
           try
           {
               Savory_ParameterList par = new Savory_ParameterList();
               par.AddStringParameter("@FirstName", firstName);
               par.AddStringParameter("@LastName", lastName);
               par.AddStringParameter("@ContactNo1", contactNo1);
               par.AddStringParameter("@ContactNo2", contactNo2);
               par.AddStringParameter("@EmailID", emailID);
               par.AddStringParameter("@CountryID", countryID);
               par.AddStringParameter("@City", city);
               par.AddIntParameter("@UserID", userID);
               par.AddStringParameter("@Office", Office);
               par.AddStringParameter("@Mobile1", MobileNo1);
               par.AddStringParameter("@Mobile2", MobileNo2);
               par.AddStringParameter("@Pwd", Password);
               par.AddBooleanTimeParameter("@IsNewslatter", IsNewslatter);
               par.AddStringParameter("@Street", Street);
               par.AddStringParameter("@FAX", Fax);
               par.AddStringParameter("@WebSite", WebSite);
               par.AddStringParameter("@UserType", UserType);
               Int32 returnStatus = Savory_DBServices.ExecuteQuery("MemberShipRegistrationStep1_New", System.Data.CommandType.StoredProcedure, par);

               if (returnStatus > 0)
               {
                   status = ResponseStatus.Success;
               }
               else 
               {
                   status = ResponseStatus.Failure;
               }
           }
           catch (Exception ex)
           {

           }
           finally
           {

           }

           return status;
       }

   }

   public class UesrDetailsList
   {
       
       public string FirstName { get; set; }
       public string IsMembership { get; set; }
       public string LastName { get; set; }
       public string Password { get; set; }
       public int UserID { get; set; }
       public bool IsActive { get; set; }
   }
}
